from openpyxl import Workbook
from openpyxl import load_workbook as load
import os
import time
from openpyxl.styles import Font, colors, Alignment

class excel:
    def __init__(self):
        self.wb = Workbook()
        #if not os.path.exists('Records/过程统计.xlsx'):
        #    wb.save('Records/过程统计.xlsx')
        #self.wb = load('Records/过程统计.xlsx')
        self.col_width=[52,50,14,16,16,16,13,15]
        self.col_lable=['A','B','C','D','E','F','G','H']

    def creat_sheet(self):
        n_sheets = len(self.wb.get_sheet_names())
        self.ws = self.wb.create_sheet('第' + str(n_sheets) + '回合', 0)


    def out_to_excel(self,ob):  # TODO (zrc) 输出每次的ob到excel
        a=1
        row=self.ws.max_row
        for infor in ob:
           cell=self.ws.cell(row=row+1,column=a)
           cell.value = str(infor)
           cell.alignment=Alignment(vertical='center',wrapText=True)
           a+=1

    def save(self):
        for i in range(8):
            self.ws.column_dimensions[self.col_lable[i]].width=self.col_width[i]
        self.wb.save('Records/过程统计/E'+time.strftime("%m-%d-%H-%M", time.localtime())+'.xlsx')


